<?php
namespace Api\Controller;
use Think\Controller;
use Think\Vender;
class GetUserInfoController extends Controller{
	protected $AppID;//小程序AppID
	protected $AppSecret;//小程序AppSecret
	protected $code;//小程序登录返回的code

	public function get_userinfo($AppID,$AppSecret,$code){
		$this->AppID = $AppID;
		$this->AppSecret = $AppSecret;
		$this->code = $code;
		$requestUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=".$this->AppID."&secret=".$this->AppSecret."&js_code=".$code."&grant_type=authorization_code";
		$result = file_get_contents($requestUrl);
		$result = json_decode($result,true);
		if($result["errcode"] > 0){
			$result["error"] = 400;
			$result["msg"] = "code获取openid 与session_keys失败";
		}else{
			$result["error"] = 200;
			$result["openid"] = $result["openid"];
			$result["session_key"] = $result["session_key"];
		}
		return $result;
	}
}
?>